#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;

using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;
using System.Collections;
using Gizmox.WebGUI.Common.Resources;
using TVC.Layout;
using System.Xml;
using System.IO;
using BUS;
using System.Text.RegularExpressions;

#endregion

namespace TVC.Modules.Business
{
    public partial class ExpenseClaim : ModuleParent, IHostedApplication
    {
        int idAllowEditLanguage = 1,
            idAddNew = 179,
            idEdit = 180,
            idUpdate = 183,
            idDelete = 181,
            idTransferOut = 1,
            idAgingReport = 182;
        int idToExcel = 258;


        bool _isCalculate = true;

        string strAction = "";
        bool bllGetData = false;

        public ExpenseClaim()
        {
            InitializeComponent();
            _strType = "ExpenseClaim";
            _dgvList = dgvExpenseClaim;
            _dgvFilter = gridFilter1;
        }

        public void InitializeApplication()
        {
        }

        public void SetObject(object obj)
        {
        }

        public HostedToolBarElement[] GetToolBarElements()
        {
            ArrayList objElements = new ArrayList();
            if (IsPermis(idAddNew)) objElements.Add(new HostedToolBarButton("Add New", "New", new IconResourceHandle("Add.png"), "C"));
            if (IsPermis(idAddNew) && IsPermis(idEdit)) objElements.Add(new HostedToolBarButton("Save", "Save", new IconResourceHandle("Save.png"), "S", false));
            if (IsPermis(idAddNew)) objElements.Add(new HostedToolBarButton("Copy", "Copy", new IconResourceHandle("Copy.png"), "O"));
            if (IsPermis(idEdit)) objElements.Add(new HostedToolBarButton("Edit", "Edit", new IconResourceHandle("Edit.png"), "A"));
            if (IsPermis(idDelete)) objElements.Add(new HostedToolBarButton("Delete", "Delete", new IconResourceHandle("Delete.png"), "X"));
            objElements.Add(new HostedToolBarButton("Skip", "Skip", new IconResourceHandle("Reject.png"), "K", false));
            if (IsPermis(idUpdate)) objElements.Add(new HostedToolBarButton("Update", "Update", new IconResourceHandle("Update.gif"), "U"));
            //if (IsPermis(idTransferOut)) objElements.Add(new HostedToolBarButton("Transfer Out", "To excel", new IconResourceHandle("excel.ico"), "TO"));
            // if (IsPermis(idEmail)) objElements.Add(new HostedToolBarButton("Email", "Email", new IconResourceHandle("OpenedMail.gif"), "M"));
            if (IsPermis(idAgingReport)) objElements.Add(new HostedToolBarButton("AgingReport", "Aging Report", new IconResourceHandle("Print.png"), "AR"));
            if (IsPermis(idToExcel)) objElements.Add(new HostedToolBarButton("To Excel", "To Excel", new IconResourceHandle("Excel.png"), "P"));
            //if (IsPermis(idAgingReport)) objElements.Add(new HostedToolBarButton("ExClaimStatus", "Ex.Claim Status", new IconResourceHandle("Method.gif"), "E"));

            objElements.Add(new HostedToolBarButton("Refresh", "Refresh", new IconResourceHandle("Refresh.png"), "R"));

            return (HostedToolBarElement[])objElements.ToArray(typeof(HostedToolBarElement));
        }
        protected override void SetupToolBar(string strAction)
        {
            ToolBar tbarLocal = GetTbarLocal();
            bool on = true, off = false;
            if (tbarLocal == null) return;

            switch (strAction)
            {
                case "C":
                case "O":
                case "A":
                    foreach (ToolBarButton button in tbarLocal.Buttons)
                    {
                        if (button.Name == "AR" || button.Name == "P") button.Enabled = on;
                        else if (!_btnProcess.Contains(button.Name))
                        {
                            if (button.Enabled != off) button.Enabled = off;
                        }
                        else { if (button.Enabled != on) button.Enabled = on; }
                    }
                    break;
                default:
                    foreach (ToolBarButton button in tbarLocal.Buttons)
                    {
                        if (button.Name == "AR" || button.Name == "P") button.Enabled = on;
                        else if (!_btnProcess.Contains(button.Name))
                        {
                            if (button.Enabled != on) button.Enabled = on;
                        }
                        else { if (button.Enabled != off) button.Enabled = off; }
                    }

                    break;
            }

        }
        public void OnToolBarButtonClick(HostedToolBarButton objButton, EventArgs objEvent)
        {
            try
            {
                string busId = GetMainForm().PODInfo.Business_ID;
                sErr = "";
                strAction = (string)objButton.Tag;

                switch (strAction)
                {
                    case "C":
                        AddNew(txtExclaimNo);
                        cboBU.Focus();
                        break;
                    case "A":
                        editRecord(txtExclaimNo);
                        cboExclaimerCode.Focus();
                        break;
                    case "S":
                        saveRecord(txtExclaimNo);
                        break;
                    case "K":
                        skip();
                        break;
                    case "O":
                        copy(txtExclaimNo);
                        txtReference.Text = "";
                        break;
                    case "X":
                        delete(txtExclaimNo);
                        break;
                    case "U":
                        DataTable dtbBatch = (DataTable)bisExpenseClaim.DataSource;
                        BatchUpdate frmBaU = new BatchUpdate(_strType, dtbBatch, GetMainForm());
                        frmBaU.ShowDialog();
                        break;
                    case "TI":
                        Forms.frmTransferIn frmTI = new Forms.frmTransferIn(_strType, GetMainForm());
                        frmTI.ShowDialog();
                        break;
                    case "TO":
                        Forms.frmTransferOut frmTO = new Forms.frmTransferOut(_strType, (DataTable)bisExpenseClaim.DataSource, GetMainForm());
                        frmTO.Show();
                        break;
                    case "R":
                        reloadList();
                        break;
                    case "AR":
                        GetMainForm().SelectCategory("QRS", "id=AgingRpt03_" + busId);
                        break;
                    case "E":
                        // GetMainForm().SelectCategory("QRS", "id=DeliveryNote_" + busId);
                        break;
                    case "M":
                        //GetMainForm().SelectCategory("QRS", "EpcStatus01");
                        break;
                    case "P":
                        export2Excel();
                        break;
                }
                if (sErr == "") ThrowMsg("Command: " + _processStatus);
            }
            catch (Exception ex)
            {
                ThrowMsg(ex.Message + Environment.NewLine + ex.Source);
            }
        }

        private void ExpenseClaim_Load(object sender, EventArgs e)
        {
            txtToday.Text = DateTime.Now.ToString("dd/MM/yyyy");
            LoadCombo();
            refreshForm("");
            enableForm(false);
        }

        private void LoadCombo()
        {
            DataTable dtb = new DataTable();

            dtb.Columns.Add("ID", typeof(string));
            dtb.Columns.Add("Name", typeof(string));
            dtb.Rows.Add("HL", "HL Hoang Long JOC");
            dtb.Rows.Add("HV", "HV Hoan Vu JOC");

            cboBU.DataSource = dtb;
            cboBU.DisplayMember = "Name";
            cboBU.ValueMember = "ID";
            //////////change DB

            BUS.SSRFANVControl ctrOrgan = new BUS.SSRFANVControl();
            DataTable dtExp = new DataTable();
            dtExp = ctrOrgan.GetAll_SSRFANVBU("T5", GetMainForm().SUNDB, ref sErr, MainForm.HLConnect);

            cboExclaimerCode.MainForm = GetMainForm();
            cboExclaimerCode.Lookup = "SSRFANV";
            cboExclaimerCode.DisplayMember = "CODE";
            cboExclaimerCode.ValueMember = "CODE";
            cboExclaimerCode.DataSource = dtExp;
            ///////////
        }

        private void Rebind()
        {
            //bisExpenseClaim.DataSource = GetMainForm().GetTable(_strType);
            gridFilter1.btnOK_Click(null, null);
        }

        #region .::| Override Functions |::.
        protected override ErrorStatus validateForm(ref string sErr)
        {
            ErrorStatus result = ErrorStatus.SUCCESS;
            sErr = "";
            errorPro.SetError(cboBU, "");
            errorPro.SetError(txtExclaimNo, "");
            errorPro.SetError(txtExclaimerName, "");
            errorPro.SetError(txtOurReference, "");
            errorPro.SetError(txtOtherAmount, "");
            errorPro.SetError(txtCurrency, "");
            errorPro.SetError(txtPaymentRef, "");

            if (cboBU.SelectedValue + "" == "")
            {
                sErr += "Business unit cannot be blank, please check!\n";
                errorPro.SetError(cboBU, "Business unit cannot be blank, please check!");
                cboBU.Focus();
                //return;
            }
            if (cboExclaimerCode.Text.Trim() != "" && string.Format("{0}", cboExclaimerCode.Value) == "")
            {
                sErr += "Exclaimer Code is not in list, please check!\n";
                errProvider.SetError(cboExclaimerCode, "Creditor is not in list!");
            }




            if (txtExclaimNo.Text.Trim() == "")
            {
                sErr += "Exclaim No cannot be blank, please check!\n";
                errorPro.SetError(txtExclaimNo, "Exclaim No cannot be blank, please check!");
                txtExclaimNo.Focus();
                //return;
            }

            if (txtExclaimerName.Text.Trim() == "")
            {
                sErr += "Exclaimer Name cannot be blank, please check!\n";
                errorPro.SetError(txtExclaimerName, "Exclaimer Name cannot be blank, please check!");
                txtExclaimerName.Focus();
                //return;
            }
            BUS.InvoiceRegisterControl invoice = new BUS.InvoiceRegisterControl();
            string busID = "HL";
            ///////=========================
            if (txtOurReference.Text != "")
            {
                string connect = Properties.Settings.Default.HLConnectString;
                string db = Properties.Settings.Default.SUNHL;
                if (cboBU.SelectedValue + "" == "HV")
                {
                    busID = "HV";
                    db = Properties.Settings.Default.SUNHV;
                }

                if (invoice.IsExistInSun(txtOurReference.Text, connect, db))
                {
                    sErr += "Our Ref. already exists in SunSystems\n";
                    errorPro.SetError(txtOurReference, "Our Ref. already exists in SunSystems");
                    txtOurReference.Focus();
                }

                /////////////

                if (invoice.IsExistOurRef(busID, txtOurReference.Text))
                {
                    sErr += "Our Ref. already exists in Invoice Register!\n";
                    errorPro.SetError(txtOurReference, "Our Ref. already exists in Invoice Register");
                    txtOurReference.Focus();
                }
            }

            BUS.ExpenseClaimControl ctrE = new BUS.ExpenseClaimControl();
            if (ctrE.IsExist_ExpenseClaimOurRef(int.Parse(txtReference.Text == "" ? "0" : txtReference.Text), txtOurReference.Text))
            {
                sErr += "Our Ref. already exists in Expense Claim!\n";
                errorPro.SetError(txtOurReference, "Our Ref. already exists in Expense Claim");
                txtOurReference.Focus();
            }

            if (txtOtherAmount.Value > 0 && txtCurrency.Text == "")
            {
                sErr += "Currency cannot be blank if Other Amount exists, please check!\n";
                errorPro.SetError(txtCurrency, "Currency cannot be blank if Other Amount exists, please check!");
                txtCurrency.Focus();
            }

            if (txtOtherAmount.Value > 0 && txtCurrency.Text == "USD")
            {
                sErr += "Currency cannot be USD if Other Amount exists, please check!\n";
                errorPro.SetError(txtCurrency, "Currency cannot be USD if Other Amount exists, please check!");
                txtCurrency.Focus();
            }

            if (txtOtherAmount.Value == 0 && txtCurrency.Text != "USD" && txtCurrency.Text != "")
            {
                sErr += "Other Amount cannot be blank if Currency exists, please check!\n";
                errorPro.SetError(txtOtherAmount, "Other Amount cannot be blank if Currency exists, please check!");
                txtOtherAmount.Focus();
            }

            if (txtPaymentRef.Text == "" && txtPaymentDate.Text != "")
            {
                sErr += "Payment Ref cannot be blank if Payment Date exists, please check!\n";
                errorPro.SetError(txtPaymentRef, "Payment Ref cannot be blank if Payment Date exists, please check!");
                txtPaymentRef.Focus();
            }


            if (ctrE.IsExist_ExpenseClaim(txtExclaimNo.Text, txtExclaimerName.Text, int.Parse(txtReference.Text == "" ? "0" : txtReference.Text)))
            {
                //MessageBox.Show("Our Ref. already exists in Invoice Register", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Warning, false);
                sErr += "Exclaim No. and Exclaimer Name already exists in Invoice Register\n";
                errorPro.SetError(txtExclaimNo, "Exclaim No. and Exclaimer Name already exists in Invoice Register");
                txtExclaimerName.Focus();
                //return;
            }

            if (sErr != "") result = ErrorStatus.ERROR;

            return result;
        }
        protected override bool checkExists()
        {
            BUS.ExpenseClaimControl ctr = new BUS.ExpenseClaimControl();
            int Reference = int.Parse(txtReference.Text == "" ? "0" : txtReference.Text);
            bool isExist = ctr.IsExist_ExpenseClaimRef(Reference);
            if (isExist) return isExist;
            return ctr.IsExist_ExpenseClaim(txtExclaimNo.Text, txtExclaimerName.Text, -1);
        }

        protected override string addRecord(bool isDraft = false)
        {
            string sErr = "";
            BUS.ExpenseClaimControl ctr = new BUS.ExpenseClaimControl();
            DTO.ExpenseClaimInfo info = GetData();
            txtReference.Text = ctr.Add_ExpenseClaim(info, ref sErr).ToString();

            return sErr;
        }
        protected override string updateRecord(bool isDraft = false)
        {
            string sErr = "";
            BUS.ExpenseClaimControl ctr = new BUS.ExpenseClaimControl();
            DTO.ExpenseClaimInfo info = GetData();
            sErr = ctr.Update_ExpenseClaim(info);
            return sErr;
        }
        protected override string delRecord()
        {
            ExpenseClaimControl ctr = new ExpenseClaimControl();
            int Reference = int.Parse(txtReference.Text == "" ? "0" : txtReference.Text);
            return ctr.Delete_ExpenseClaimRef(Reference);

        }

        protected override void refreshForm(string str)
        {
            _isCalculate = false;
            gbPrimary.SuspendLayout();
            txtReference.Text = "";
            cboBU.SelectedValue = "";
            txtExclaimNo.Text = "";
            cboExclaimerCode.Text = "";
            txtExclaimerName.Text = "";
            txtSupportingDoc.Text = "";
            txtOurReference.Text = "";
            txtIssuedDate.Text = "";
            txtReceivedDate.Text = "";
            txtCurrency.Text = "";
            txtOtherAmount.Value = 0;
            txtAmount.Value = 0;
            txtPaymentTerm.Value = 0;
            txtDueDate.Text = "";
            txtPaymentDate.Text = "";
            txtPaymentRef.Text = "";
            txtDescription.Text = "";
            txtDepartmentHeld.Text = "";
            chkEmailed.Checked = true;
            txtRemark1.Text = "";
            txtRemark2.Text = "";
            txtRemark3.Text = "";
            txtPaidOtherAmount.Value = 0;
            txtPaidAmount.Value = 0;
            gbPrimary.ResumeLayout(true);
            _isCalculate = true;
        }
        protected override void enableForm(bool val)
        {
            gbPrimary.SuspendLayout();
            cboBU.Enabled = val;
            txtExclaimNo.Enabled = val;
            cboExclaimerCode.Enabled = val;
            txtExclaimerName.Enabled = val;
            txtSupportingDoc.Enabled = val;
            txtOurReference.Enabled = val;
            txtIssuedDate.Enabled = val;
            txtReceivedDate.Enabled = val;
            txtCurrency.Enabled = val;
            txtOtherAmount.Enabled = val;
            txtAmount.Enabled = val;
            txtPaymentTerm.Enabled = val;
            txtDueDate.Enabled = val;
            txtPaymentDate.Enabled = val;
            txtPaymentRef.Enabled = val;
            txtDescription.Enabled = val;
            txtDepartmentHeld.Enabled = val;
            chkEmailed.Enabled = val;
            txtRemark1.Enabled = val;
            txtRemark2.Enabled = val;
            txtRemark3.Enabled = val;
            txtPaidAmount.Enabled = val;
            txtPaidOtherAmount.Enabled = val;

            if (val == false)
            {
                foreach (Control x in gbPrimary.Controls)
                {
                    if (errProvider.GetError(x) != string.Empty) errProvider.SetError(x, "");
                }
            }
            gbPrimary.ResumeLayout(true);
        }

        protected override void loadRecord(object o)
        {
            if (o is DataRowView)
            {
                DTO.ExpenseClaimInfo inf = new DTO.ExpenseClaimInfo((DataRowView)o);
                SetData(inf);
            }
        }

        #endregion


        private void SetData(DTO.ExpenseClaimInfo info)
        {
            gbPrimary.SuspendLayout();
            _isCalculate = false;
            txtReference.Text = info.Reference.ToString();
            cboBU.SelectedValue = info.Business;
            txtExclaimNo.Text = info.ExcNo;
            cboExclaimerCode.Value = info.EmployeeCode;
            txtExclaimerName.Text = info.EmployeeName.Trim();
            txtSupportingDoc.Text = info.SupportDoc;
            txtOurReference.Text = info.OurRef;
            txtIssuedDate.Text = (info.IssueDate == DateTime.MinValue ? "" : info.IssueDate.ToString("dd/MM/yyyy"));
            txtReceivedDate.Text = (info.ReceiptDate == DateTime.MinValue ? "" : info.ReceiptDate.ToString("dd/MM/yyyy"));
            txtCurrency.Text = info.Currency;
            txtOtherAmount.Text = info.OtherAmt.ToString();
            txtAmount.Text = info.Amt.ToString();
            txtPaymentTerm.Text = info.PaymentTerm.ToString();
            txtDueDate.Text = (info.DueDate == DateTime.MinValue ? "" : info.DueDate.ToString("dd/MM/yyyy"));
            txtPaymentDate.Text = (info.PaidDate == DateTime.MinValue ? "" : info.PaidDate.ToString("dd/MM/yyyy"));
            txtPaymentRef.Text = info.PymtRef;
            txtDescription.Text = info.Description;
            txtDepartmentHeld.Text = info.Department;
            chkEmailed.Checked = bool.Parse(info.Emailed.ToString() == "1" ? "true" : "false");
            txtRemark1.Text = info.Remark1;
            txtRemark2.Text = info.Remark2;
            txtRemark3.Text = info.Remark3;
            txtPaidOtherAmount.Text = info.PaidOtherAmt.ToString();
            txtPaidAmount.Text = info.PaidAmt.ToString();
            _isCalculate = true;
            gbPrimary.ResumeLayout(true);
        }

        private DTO.ExpenseClaimInfo GetData()
        {
            return new DTO.ExpenseClaimInfo(
                cboBU.SelectedValue.ToString(),
                int.Parse(txtReference.Text == "" ? "0" : txtReference.Text),
                txtExclaimNo.Text,
                //cboExclaimerCode.Text,
                txtExclaimerName.Text.Trim(),
                txtSupportingDoc.Text,
                txtOurReference.Text,
                txtIssuedDate.Value,
                txtReceivedDate.Value,
                double.Parse(txtAmount.Text == "" ? "0" : txtAmount.Text),
                double.Parse(txtOtherAmount.Text == "" ? "0" : txtOtherAmount.Text),
                txtCurrency.Text,
                txtPaymentRef.Text,
                txtPaymentDate.Value,
                int.Parse(txtPaymentTerm.Text == "" ? "0" : txtPaymentTerm.Text),

                (txtReceivedDate.Text == "" ? txtDueDate.Value : txtReceivedDate.Value),

                txtDescription.Text,
                DateTime.MinValue,
                DateTime.MinValue,
                txtDepartmentHeld.Text,
                short.Parse(chkEmailed.Checked ? "1" : "0"),
                txtRemark1.Text,
                txtRemark2.Text,
                txtRemark3.Text,
                0, "",
                DateTime.MinValue,
                0, "", "", cboExclaimerCode.Text,
                double.Parse(txtPaidAmount.Text == "" ? "0" : txtPaidAmount.Text),
                double.Parse(txtPaidOtherAmount.Text == "" ? "0" : txtPaidOtherAmount.Text),
                0, GetMainForm().PODInfo.USER_ID, GetMainForm().PODInfo.USER_ID,
                DateTime.Now,
                DateTime.Now
                //float.Parse(txtPaidOtherAmount.Text == "" ? "0" : txtPaidOtherAmount.Text),
                //txtPaidAmount.Text
                );

        }

        private void gridFilter1_GridFiterEvent(string strFilter, int year)
        {
            string sErr = "";
            BUS.ExpenseClaimControl ctrExc = new BUS.ExpenseClaimControl();
            //if (strFilter.Trim() != "" && year > 0)
            //    strFilter = strFilter + " and year(IssueDate) = " + year.ToString();
            //else if (strFilter.Trim() == "" && year > 0)
            //    strFilter = strFilter + " year(IssueDate) = " + year.ToString();
            FormatDate();
            DataTable dtb = ctrExc.GetCond(strFilter, ref sErr);
            if (!string.IsNullOrEmpty(gridFilter1.SortField))
            {
                dtb.DefaultView.Sort = gridFilter1.SortField + " " + gridFilter1.Direction;
            }
            bisExpenseClaim.DataSource = dtb;

            DataTable dtbAmt = ctrExc.GetSumAmt(strFilter, ref sErr);
            if (dtbAmt != null) txtTotalAmount.Value = decimal.Parse(dtbAmt.Rows[0][0].ToString() == "" ? "0" : dtbAmt.Rows[0][0].ToString());

            DataTable dtbOtherAmt = ctrExc.GetSumOtherAmt(strFilter, ref sErr);
            if (dtbAmt != null)
                txtTotalOtherAmount.Value = decimal.Parse(dtbOtherAmt.Rows[0][0].ToString() == "" ? "0" : dtbOtherAmt.Rows[0][0].ToString());
        }

        private void txt_DoubleClick(object sender, EventArgs e)
        {
            TextBox txt = (TextBox)sender;
            MessageBox.Show(txt.Text, "Full text");
        }



        private void cboExclaimerC_SelectedIndexChanged(object sender, EventArgs e)
        {
            //if (cboExclaimerC.SelectedIndex >= 0)
            //{
            //    cboExclaimerCode.Text = cboExclaimerC.SelectedValue.ToString();
            //    txtExclaimerName.Text = ((DataTable)cboExclaimerC.DataSource).Rows[cboExclaimerC.SelectedIndex]["NAME"].ToString().Trim();
            //}
        }

        private void chkEmailed_CheckedChanged(object sender, EventArgs e)
        {
            if (_isCalculate)
            {
                if (chkEmailed.Checked == false)
                {
                    MessageBox.Show("Are you sure to uncheck sent email? This Expense Claim will be emailed again?", "Confirm", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, delegate(object newSender, EventArgs newArgs)
                    {
                        if (((MessageBoxWindow)newSender).DialogResult == DialogResult.OK) chkEmailed.Checked = false;

                        else chkEmailed.Checked = true;
                    }, false);
                }
            }
        }

        private void txtOtherAmount_Enter(object sender, EventArgs e)
        {
            (sender as NumericUpDown).Select(0, (sender as NumericUpDown).ToString().Length);
        }

        private void cboExclaimerCode_SelectedValueChanged(object sender, EventArgs e)
        {
            if (cboExclaimerCode.SelectedItem is DataRowView)
                txtExclaimerName.Text = ((DataRowView)cboExclaimerCode.SelectedItem)["NAME"].ToString().Trim();
        }

        private void cboExclaimerCode_Leave(object sender, EventArgs e)
        {
            if (cboExclaimerCode.Text != null && cboExclaimerCode.Text.Trim() != "")
            {
                if (cboExclaimerCode.Value.ToString().Trim() == "")
                {
                    cboExclaimerCode.Focus();
                    MessageBox.Show(" Please select from the list ", false);
                }
            }

        }

        private void txtReceivedDate_OnDateChange(object sender, EventArgs e)
        {
            if (_isCalculate)
            {
                _isCalculate = false;
                if (txtReceivedDate.Text.Trim() != "")
                {
                    try
                    {
                        DateTime reciveDate = txtReceivedDate.Value;// DateTime.ParseExact(, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
                        if (Regex.IsMatch(txtPaymentTerm.Text, "^[0-9]+$")) txtDueDate.Text = reciveDate.AddDays(Convert.ToInt32(txtPaymentTerm.Text)).ToString("dd/MM/yyyy");
                        //if (Regex.IsMatch(txtPaymTerm.Text, "^[0-9]+$")) txtDueDate.Text = reciveDate.AddDays(Convert.ToInt32(txtPaymTerm.Text)).ToString("dd/MM/yyyy");
                        // txtDueDate.Value = reciveDate

                    }
                    catch (Exception ex)
                    {
                        sErr = ex.Message;
                        //errProvider.SetError(txtReceivedDate, "Invalide format datetime");
                    }
                }
                _isCalculate = true;
            }
        }

        private void txtPaymentTerm_ValueChanged(object sender, EventArgs e)
        {
            if (_isCalculate)
            {
                _isCalculate = false;
                DateTime reciveDate = txtReceivedDate.Value;
                if (Regex.IsMatch(txtPaymentTerm.Text, "^[0-9]+$")) txtDueDate.Text = reciveDate.AddDays(Convert.ToInt32(txtPaymentTerm.Text)).ToString("dd/MM/yyyy");
                _isCalculate = true;
            }
        }
    }
}